/*
 * @Author: liaoshuang 345324985@qq.com
 * @Date: 2023-12-22 11:05:39
 * @LastEditors: liaoshuang 345324985@qq.com
 * @LastEditTime: 2024-04-01 16:41:18
 * @FilePath: \h5-pad-vue2\src\lang\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import { Locale } from 'vant';
import zhCN from 'vant/es/locale/lang/zh-CN';
import enUS from 'vant/es/locale/lang/en-US';
import zh from './zh'
import en from './en'

Vue.use(VueI18n)
const messages = {
  en: {
    ...en,
  },
  zh_CN: {
    ...zh,
  },
}
const language = (navigator.language || 'en').toLocaleLowerCase() // 这是获取浏览器的语言 language.split('-')[0]
const locale = localStorage.getItem('lang') || 'en' // 首先从缓存里拿，没有的话就用浏览器语言，
if(locale === 'zh_CN')  {
  Locale.use('zh-CN', zhCN);
} else if(locale === 'en')  {
  Locale.use('en-US', enUS);
}

const i18n = new VueI18n({
  locale,
  fallbackLocale: 'en', // 设置备用语言
  messages, 
})

export default i18n

